<?php 
namespace app\adm\controller;

class Tips extends Base {

	public function index ()
	{
		if (is_post()) {
			$post = input('post.');
			if (input('get.acc') == 'edit') {
				if ($id = $post['id']) {
					unset($post['id']);
					$rst = db('tips_base')->where('id',$id)->update($post);
					if ($rst)
						$this->success('修改成功');
					$this->error('修改失败');
				}
				$post['soft_del'] = 1;
				$post['reletime'] = date('Y-m-d H:i:s',time());
				$rst = db('tips_base')->insert($post);
				if ($rst) 
					$this->success('添加成功');
				$this->error('添加失败');
			}
			if (input('get.acc') == 'get') {
				$data = db('tips_base')->where('id',input('post.id'))->find();
				return $data;
			}
			if (input('get.acc') == 'rm') {
				$rst = db('tips_base')->where('id',input('post.id'))->setField('soft_del',0);
				if ($rst)
					$this->success('删除成功');
				$this->error('请稍后重试');
			}
		}

		$data = db('tips_base')->where('soft_del',1)->paginate();
		$this->assign('list',$data);
		return $this->fetch();
	}

	public function listt ()
	{
		$data = db('tips_log')->paginate();
		$this->assign('list',$data);
		return $this->fetch();
	}
}